<template>
	<view class="page-content">
		<u-loading-page :loading="loading" bg-color="#e8e8e8"></u-loading-page>
		<u--form labelWidth='auto' labelAlign="left" labelPosition="left" :model="detailform" :rules="rules"
			ref="form1">
			<u-form-item label="长者姓名" prop="name" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.name"></u--text>
			</u-form-item>
			<u-form-item label="性别" prop="sex" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.sex"></u--text>
			</u-form-item>
			<u-form-item label="身份证号码" prop="idNumber" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.idNumber"></u--text>
			</u-form-item>
			<u-form-item label="联系电话" prop="phone" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.phone"></u--text>
			</u-form-item>
			<u-form-item label="年龄" prop="age" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="GetAgeByIdCard(detailform.idNumber)"></u--text>
			</u-form-item>
			<u-form-item label="居住地址" prop="name" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="getPermanentAddress(detailform)"></u--text>
			</u-form-item>
			<u-form-item label="户籍地址" prop="name" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="getHouseholdAddress(detailform)"></u--text>
			</u-form-item>
			<u-form-item label="居住状况" prop="livingStatus" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.livingStatus"></u--text>
			</u-form-item>
			<u-form-item label="经济来源" prop="econSources" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.econSources"></u--text>
			</u-form-item>

			<u-line color="#2979ff"></u-line>

			<u-form-item label="紧急联系人姓名" prop="emergencyContactName" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.emergencyContactName"></u--text>
			</u-form-item>
			<u-form-item label="紧急联系人电话" prop="emergencyContactPhone" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.emergencyContactPhone"></u--text>
			</u-form-item>
			<u-form-item label="紧急联系人与老年人关系" prop="emergencyContactKinship" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.emergencyContactKinship"></u--text>
			</u-form-item>

			<u-line color="#2979ff"></u-line>

			<u-form-item label="意识水平测评" prop="consciousnessLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.consciousnessLevel"></u--text>
			</u-form-item>
			<u-form-item label="沟通交流测评" prop="communicationLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.communicationLevel"></u--text>
			</u-form-item>
			<u-form-item label="视力测评" prop="eyesightLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.eyesightLevel"></u--text>
			</u-form-item>
			<u-form-item label="听力测评" prop="hearingLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.hearingLevel"></u--text>
			</u-form-item>
			<u-form-item label="认知功能测评" prop="acknowledgeLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.acknowledgeLevel"></u--text>
			</u-form-item>
			<u-form-item label="攻击行为测评" prop="attackLvel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.attackLvel"></u--text>
			</u-form-item>
			<u-form-item label="抑郁症状测评" prop="depressionLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.depressionLevel"></u--text>
			</u-form-item>
			<u-form-item label="工作能力测评" prop="workcapabilityLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.workcapabilityLevel"></u--text>
			</u-form-item>
			<u-form-item label="人物定向测评" prop="directionalLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.directionalLevel"></u--text>
			</u-form-item>
			<u-form-item label="社会交往能力测评" prop="relationshipLevel" borderBottom ref="item1">
				<u--text bold margin="5px" align="right" :text="detailform.relationshipLevel"></u--text>
			</u-form-item>
		</u--form>
		<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" @click="handel_edit_click" type="success" size="small">编辑
				</u-button>
			</u-col>
		</u-row>
		<u-row customStyle="margin:10px">
			<u-col span="12">
				<u-button class="custom-style" @click="handel_delete_click" :disabled="disabled_Delete" type="error"
					size="small">删除
				</u-button>
			</u-col>
		</u-row>
		<u-modal :show="show" :showCancelButton="true" :content='content' @confirm="handle_confirmDelete_click"
			@cancel="handle_confirmCancel_click"></u-modal>
	</view>
</template>

<script>
	import {
		transformPostBody,
		transformRequestURL
	} from "@/utils/requestParams.js";
	import {
		QueryRTInfoList,
		addRTInfo,
		updateRTInfo,
		getRTInfo,
		delRTInfo,
		QueryRTInfoHistory
	} from "@/api/elder/RTInfo.js";

	import {
		GetAgeByIdCard
	} from "@/utils/stringFormat.js";

	export default {
		data() {
			return {
				GetAgeByIdCard: GetAgeByIdCard,
				id: null,
				detailform: {},
				loading: false, //加载中
				show: false, //删除确认窗口
				content: '确认删除此条老人信息?',
				rules: {},
			}
		},
		onLoad: function(options) {
			console.log('options', options.id)
			this.id = options.id //将老人id保存
		},
		onShow() {
			this.getList();
		},
		computed: {
			disabled_Delete() {
				// return !this.$auth.hasRole("admin")
				return false
			},
			//获取居住地址
			// "permanentProvince": "山西省",
			//     "permanentCity": "威海文登市",
			//     "permanentDistrict": "离石区",
			//     "permanentTown": "",
			//     "permanentVillage": "城东社区",
			//     "permanentStreet": "滨河街道",
			//     "permanentResidenceAdd": "滨河佳苑后散户5排4院",
			getPermanentAddress() {
				return function(item) {
					let result = "";
					if (item.permanentCity) result += item.permanentCity
					if (item.permanentDistrict) result += item.permanentDistrict
					// if (item.permanentTown) result += item.permanentTown
					if (item.permanentStreet) result += item.permanentStreet
					if (item.permanentVillage) result += item.permanentVillage
					if (item.permanentResidenceAdd) result += item.permanentResidenceAdd
					return result
				}
			},
			//获取户籍地址
			// "householdProvince": "山西省",
			//     "householdCity": "威海文登市",
			//     "householdDistrict": "离石区",
			//     "householdTown": "",
			//     "householdVillage": "",
			//     "householdStreet": "",
			//     "householdRegisterAdd": "",
			getHouseholdAddress() {
				return function(item) {
					let result = "";
					if (item.householdCity) result += item.householdCity
					if (item.householdDistrict) result += item.householdDistrict
					if (item.householdTown) result += item.householdTown
					if (item.householdVillage) result += item.householdVillage
					if (item.householdStreet) result += item.householdStreet
					if (item.householdRegisterAdd) result += item.householdRegisterAdd
					return result
				}
			},

		},
		methods: {

			getList() {
				this.loading = true;
				getRTInfo(this.id).then((response) => {
					this.loading = false;
					console.log("getRTInfo", response);
					this.detailform = Object.assign({}, this.detailform, response.data)
				});
			},

			//跳转编辑页面
			handel_edit_click() {
				this.$tab.navigateTo('/pages/RTInfo/edit?id=' + this.id)
			},

			//删除设备信息
			handel_delete_click() {
				this.show = true;
			},
			//确认删除
			handle_confirmDelete_click() {
				this.loading = true;
				delRTInfo([this.id]).then((response) => {
					console.log("delRTInfo", response);
					if (response.code != 200) {
						uni.$u.toast(response.msg)
						this.loading = false;
						this.show = false;
					} else {
						uni.$u.toast('删除成功')
						this.loading = false;
						this.show = false;
						this.$tab.navigateBack();
					}
				}).catch(errors => {
					console.log("errors", errors, this.id);
					uni.$u.toast('删除失败')
				});
			},
			//取消删除
			handle_confirmCancel_click() {
				this.show = false;
			}

		},
	}
</script>

<style lang="scss">
	page {
		background-color: white;
		display: flex;
		justify-content: center;
	}

	.page-content {
		width: 93%;
	}

	.custom-style {
		width: 80%;
		font-weight: bolder;
		font-size: 17px;
	}
</style>